package com.mail.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mail.dubbo.mapper.UmsRoleResourceRelationMapper;
import com.mail.model.db.UmsRoleResourceRelation;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author 吕永乐
 * @date 2022/06/23 11:53
 **/
@DubboService
public class UmsRoleResourceRelationApiImpl implements UmsRoleResourceRelationApi{

	@Autowired
	private UmsRoleResourceRelationMapper umsRoleResourceRelationMapper;

	/**
	 * 根据 roleId 查询
	 *
	 * @param roleId
	 * @return
	 */
	@Override
	public List<UmsRoleResourceRelation> getByRoleId(Long roleId) {
		LambdaQueryWrapper<UmsRoleResourceRelation> wrapper = new LambdaQueryWrapper<>();
		wrapper.eq(UmsRoleResourceRelation::getRoleId, roleId);
		return umsRoleResourceRelationMapper.selectList(wrapper);
	}

	/**
	 * 首先根据 roleId 删除 对应的数据
	 *
	 * @param roleId
	 */
	@Override
	public void removeByRoleId(Long roleId) {
		LambdaQueryWrapper<UmsRoleResourceRelation> wrapper = new LambdaQueryWrapper<>();
		wrapper.eq(UmsRoleResourceRelation::getRoleId, roleId);
		umsRoleResourceRelationMapper.delete(wrapper);
	}

	/**
	 * 添加
	 *
	 * @param umsRoleMenuRelation
	 */
	@Override
	public void save(UmsRoleResourceRelation umsRoleMenuRelation) {
		umsRoleResourceRelationMapper.insert(umsRoleMenuRelation);
	}
}
